package com.tuozixuan.singleton1;;

/**
 * 同步锁单例模式2<br/>
 * 用synchronized代码块包装if (instance == null)条件，并指定SingletonSync2.class对象来提供锁<br/>
 * 
 * @see Singleton
 * @see SingletonSync
 * @author tuozixuan
 *
 */
public class SingletonSync2 {
	
	private static SingletonSync2 instance;
	
	private SingletonSync2() {
		System.out.println("Something is Instantiated.");
	}
	
	public static SingletonSync2 getInstance() {
		
		synchronized(SingletonSync2.class) {
			if (instance == null) {
				instance = new SingletonSync2();
			}
		}
		return instance;
	}
	
	public void doSomething() {
		System.out.println("Something is Done.");
		
	}
}
